<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Keu_list_jurnal extends MY_Controller {
	
	function __construct()
	{
		parent::__construct(); 
		
		$this->load->model('keu_list_jurnal_model', 'GLTrans');
		$this->load->model('keu_transaksi_detail_model', 'GLTransDetail');
		$this->load->model('combo_model', 'Combo');
		
		$this->secure_session();
	}
	
	function index(){
		$data['title'] = $this->session_menu_label;
		$data['data'] = null;
		$data['data']['date_from'] = date('01/m/Y');
		$data['data']['date_to'] = date('t/m/Y');
		
		
		$data['kd_tipe_jurnal'] = json_encode(array_merge(array(array('value'=>'','display'=>'')), $this->Combo->KeuTipeJurnal()));
		
		viewByTemplate('keu_list_jurnal/index', $data, 'grid');
	}
	
	function getdata()
	{
		$this->secure_session();
		echo $this->GLTrans->GetJSON();
	}
	
	function getdetaildata()
	{
		$this->secure_session();
		echo $this->GLTrans->GetDetailJSON(post('id_dok'));
	}
	
	
	
	function dtl_account_data()
	{
		echo $this->GLTransDetail->GetJSON();
	}
	
	
	function print_voucher(){
		$as_doc_id	= get('id_dok');
		
		if($as_doc_id != ''){
			
			// Load FPDF
			$this->load->helper('fpdf');
			
			// Set Data
			$result	= $this->db->query("SELECT	KEU_TRANSAKSI.*, KEU_TIPE_JURNAL.INWARD
										FROM KEU_TRANSAKSI INNER JOIN KEU_TIPE_JURNAL 
											ON KEU_TIPE_JURNAL.KD_TIPE_JURNAL = KEU_TRANSAKSI.KD_TIPE_JURNAL
										WHERE KEU_TRANSAKSI.ID_DOK = '".$as_doc_id."'");
			
			
			$data['data']		= $result->row_array();
			
			
			$result	= $this->db->query("SELECT	TD.*, COA.NAMA_COA, CC.NAMA_COST_CENTER
										FROM	KEU_TRANSAKSI_DETAIL TD
												LEFT JOIN KEU_COA COA ON COA.ID_COA = TD.ID_COA
												LEFT JOIN SW_COST_CENTER CC ON TD.KD_COST_CENTER = CC.ID_COST_CENTER_PK
										WHERE	
												TD.ID_DOK = '".$as_doc_id."'
												AND (NVL(TD.DEBET, 0)> 0 or NVL(TD.KREDIT, 0)> 0)
										ORDER BY NVL(TD.DEBET,0) DESC, TD.ID_COA ");
			if($result->num_rows() >0){
				$data['arr_detail']	= $result->result_array();
			}else{
				$data['arr_detail']	= array();
			}
						
			// Load View
			
			if ($data['data']['inward']=='O'){
				$this->load->view('keu_list_jurnal/print_penerimaan', $data);
			}else if ($data['data']['inward']=='I'){
				$this->load->view('keu_list_jurnal/print_pembayaran', $data);
			}else{
				$this->load->view('keu_list_jurnal/print_voucher', $data);
			}
			
		}
	}
}
?>